//
//  RwdSearchView.swift
//  Weibo_rwd
//
//  Created by 任文迪 on 16/7/13.
//  Copyright © 2016年 spaceX. All rights reserved.
//

import UIKit

class RwdSearchView: UIView,UITextFieldDelegate {
    
    
    @IBOutlet weak var rightAliment: NSLayoutConstraint!
    @IBOutlet weak var cancelButton: UIButton!
    @IBOutlet weak var searchField: UITextField!
    //加载xib
    class func searchView()-> RwdSearchView {
        
        
        
        return UINib(nibName: "SearchView", bundle: nil).instantiateWithOwner(nil, options: nil).last! as! RwdSearchView
        
    }
    //监听textview的点击事件
    func textFieldDidBeginEditing(textField: UITextField) {
        //右侧约束修改
        rightAliment.constant = cancelButton.frame.size.width
        //动画方式
        UIView.animateWithDuration(0.25) { () -> Void in
            self.layoutIfNeeded()
        }
    }
    @IBAction func cancelAction(sender: AnyObject) {
        
        searchField.resignFirstResponder()
        rightAliment.constant = 0
        //动画方式
        UIView.animateWithDuration(0.25) { () -> Void in
            self.layoutIfNeeded()
        }
        
    }
    

}
